<?php if( !defined( 'MAIN_DIR' ) ) { header( 'Location: ' . dirname( PHP_SELF ) . '/' ); exit( ); }

	$lightboxes = ( isset( $_POST['lightboxes'] ) && $_POST['lightboxes'] ? $_POST['lightboxes'] : null );
	$download = ( !isset( $download ) || $download == true );
	
	if( $download && ( !isset( $_SERVER['HTTP_FLASH_UUID'] ) || $_SERVER['HTTP_FLASH_UUID'] != "oviedo-nd-zl" ) )	{
		echo "error=true&msg=Acceso Denegado";
		exit( );
	}
	
	define( '_MPDF_PATH', SWAT_DIR . 'classes/external/mpdf/' );
	include( _MPDF_PATH . 'mpdf.php' );
	
	$mpdf = new mPDF( 'iso-8859-2', array( 400, 210 ) );
	$mpdf->use_embeddedfonts_1252 = true;
	
	ob_start( );
?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
	<td align="left">
		<img src="../images/pdfOviedo.jpg" width="780" height="80" alt="Alberto Oviedo" />
    </td>
</tr>
</table>
<?php
	$content = ob_get_contents( );
	ob_clean( );
	$mpdf->SetHTMLHeader( $content );
	
	
	$lightboxes = explode( ',', $lightboxes );
	$files = array( );
	
	foreach( $lightboxes as $id )	{
		$file = new File( );
		if( $file->load( (int)$id ) && $file->getFileType( ) == 'Photo' && $file->getProperty( 'image' ) )
			$files[] = $file;
	}
	
	
	ob_start( );
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td height="180">&nbsp;</td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<?php
	for( $c = 0, $max = count( $files ); $c < $max; $c++ )	{
?>
	<td width="2"></td>
	<td width="190" height="140" align="center" valign="middle" style="border:1px solid #EEE"><img src="../uploads/<?= str_replace( '_n.', '_m.', toURL( $files[$c]->getProperty( 'image' ) ) ) ?>" alt="" border="0" /></td>
	<td width="3"></td>
<?php
	}
?>
</tr>
</table>
<?php

	$content = ob_get_contents( );
	ob_clean( );
	$mpdf->WriteHTML( $content );
	
	ob_start( );
?>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
	<td width="80%">
		<font face="Arial, Helvetica, sans-serif" size="5" color="#7F7F7F">
			Represented by: FOX CREATIVE
			<br />
			LA: 323 8451760
			<br />
			San Francisco: 415 6427058
			<br />
			New York: 212 3750450 
			<br />
			<a href="mailto:info@foxcreative.com" style="color:#7F7F7F">info@foxcreative.com</a>
			<br />
			&copy; 2009 Alberto Oviedo
		</font>
	</td>
	<td valign="middle" align="right"><img src="../images/pdfLogo.jpg" width="200" height="165" alt="Alberto Oviedo" /></td>
</tr>
</table>
<?php

	$content = ob_get_contents( );
	ob_clean( );
	$mpdf->SetHTMLFooter( $content );
	
	$path = BASE_DIR . DIRECTORY_SEPARATOR . 'pdfs' . DIRECTORY_SEPARATOR;
	$file = 'AlbertoOviedo-' . implode( '-', $lightboxes ) . '.pdf';
	$mpdf->Output( $path . $file, 'F' );
	
	if( $download )	{
		header( "Pragma: public" );
		header( "Expires: 0" );
		header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
		header( "Cache-Control: private", false );
		header( "Content-Type: application/x-download" );
		header( "Content-Disposition: attachment; filename=\"" . $file . "\";" );
		header( "Content-Transfer-Encoding: binary");
		header( "Content-Length: ". @filesize( $path . $file ) );
		
		@readfile( $path . $file );
	}
?>